<?php

/**
 * This is the model class for table "dede_arctiny".
 *
 * The followings are the available columns in table 'dede_arctiny':
 * @property integer $id
 * @property integer $typeid
 * @property string $typeid2
 * @property integer $arcrank
 * @property integer $channel
 * @property string $senddate
 * @property string $sortrank
 * @property integer $mid
 */
class Arctiny extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Arctiny the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
	/**
     * Prepares senddate, sortrank, mid ,arcrank  and
     * typeid2 ,  id attributes before performing validation.
     */
    protected function beforeValidate() {
 
        if ($this->isNewRecord) {
            // set the senddate and so on
            $this->senddate = $this->sortrank = time();
			$this->arcrank = $this->typeid2 = 0;
            $this->mid = $this->channel = 1;
			
			
        }
        return parent::beforeValidate();
    }

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'dede_arctiny';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('mid', 'required'),
			array('typeid, arcrank, channel, mid', 'numerical', 'integerOnly'=>true),
			array('typeid2', 'length', 'max'=>90),
			array('senddate, sortrank', 'length', 'max'=>10),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, typeid, typeid2, arcrank, channel, senddate, sortrank, mid', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'typeid' => 'Typeid',
			'typeid2' => 'Typeid2',
			'arcrank' => 'Arcrank',
			'channel' => 'Channel',
			'senddate' => 'Senddate',
			'sortrank' => 'Sortrank',
			'mid' => 'Mid',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('typeid',$this->typeid);
		$criteria->compare('typeid2',$this->typeid2,true);
		$criteria->compare('arcrank',$this->arcrank);
		$criteria->compare('channel',$this->channel);
		$criteria->compare('senddate',$this->senddate,true);
		$criteria->compare('sortrank',$this->sortrank,true);
		$criteria->compare('mid',$this->mid);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}